#pragma once

#include "LinkedList.h"

class CAcceptSocket;
class CDataToSendNode : public CLinkedNode
{
public:
	CDataToSendNode(const byte*d, intptr_t dLen, LPVOID ctx) : context(ctx)
	{
		dataLength = d ? max(0, dLen) : 0;
		if (dataLength)
		{
			data = (const byte*)HeapAlloc(GetProcessHeap(), 0, dataLength);
			if (data) memcpy_s((LPVOID)data, dataLength, d, dataLength);
		}
		else
			data = nullptr;
	}
	~CDataToSendNode() override
	{
		if (data) HeapFree(GetProcessHeap(), 0, (LPVOID)data);
	}
	const byte *getData() { return data; }
	intptr_t getDataLength() { return dataLength; }
	LPVOID getContext() { return context; }
	bool AcceptSend(CAcceptSocket *sock);
protected:
	LPVOID context;
	intptr_t dataLength;
	const byte* data;
};

class CDataToSendList :public CLinkedList
{
public:
	CDataToSendNode *GetNode() override
	{
		return (CDataToSendNode *)CLinkedList::GetNode();
	}
};
